﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics.Contracts;

namespace SoftwareEngineering.Modeling
{
  public interface ILazyActionExecutor
  {
    void AddAction(Action action);
  }
  public class LazyActionExecutor : ILazyActionExecutor, IDisposable
  {
    List<Action> actions = new List<Action>();

    public void AddAction(Action action)
    {
      Contract.Requires(action != null);
      Contract.Requires(actions != null);

      actions.Add(action);
    }

    public void Dispose()
    {
      Contract.Requires(actions != null);

      foreach (var action in actions)
      {
        action();
      }
      actions = null;

      GC.SuppressFinalize(this);
    }
  }
}
